#ifndef VIEWPORT_H
#define VIEWPORT_H

#include "GL/glew.h"
#include "GL/glfw.h"
#include "Common/Macro.h"
#include "Common/Output.h"
#include "Maths/Math.h"
#include "Maths/Matrix.h"
#include "Maths/Quaternion.h"


class Viewport
{
public:
					Viewport			(void);
	virtual			~Viewport			(void);
			void	Init				();
			void	InitProjectionMat	(float FOV, float aWidth, float aHeight, float zNear, float zFar);
	inline	void	Update				();
	inline	void	SetWidth			(float aWidth)	;
	inline	void	SetHeight			(float aHeight)	;
	inline	void	SetFOV				(float aFOV)	;
	inline	void	SetZNear			(float aZNear)	;
	inline	void	SetZFar				(float aZFar)	;

	inline	Matrix& GetProjectionMatrix();

private:
			void	ComputeProjectionMat();

private:

	bool mDirty;
	float mWidth;
	float mHeight;
	float mFOV;
	float mZNear;
	float mZFar;
	Matrix mProjectionMatrix;
};

//////////////////////////////////////////////////////////////////////////
inline Matrix& Viewport::GetProjectionMatrix()
{
	Update();
	return mProjectionMatrix; 
}

//////////////////////////////////////////////////////////////////////////
void Viewport::Update()
{
	if (mDirty)
	{
		ComputeProjectionMat();
	}
}

//////////////////////////////////////////////////////////////////////////
inline void Viewport::SetWidth(float aWidth) 
{ 
	if (aWidth != mWidth)
	{
		mDirty = true;
		mWidth = aWidth; 
	}
}
//////////////////////////////////////////////////////////////////////////
inline void Viewport::SetHeight(float aHeight) 
{ 
	if (mHeight != aHeight)
	{
		mDirty = true;
		mHeight = aHeight; 
	}
	
}
//////////////////////////////////////////////////////////////////////////
inline void Viewport::SetFOV(float aFOV)		 
{
	if (aFOV != mFOV)
	{
		mDirty = true;
		mFOV = aFOV;
	}
}
//////////////////////////////////////////////////////////////////////////
inline void Viewport::SetZNear(float aZNear) 
{
	if (aZNear != mZNear)
	{
		mDirty = true;
		mZNear = aZNear;
	}
}
//////////////////////////////////////////////////////////////////////////
inline void Viewport::SetZFar(float aZFar)	
{  
	if (aZFar != mZFar)
	{
		mDirty = true;
		mZFar = aZFar;
	}
}
#endif // Viewport_H

